package com.polaris.live.common.util

import android.text.BidiFormatter
import android.text.TextDirectionHeuristics
import com.hjq.language.MultiLanguages
import java.util.Locale

/**
 * AppUitls
 *
 * @author Created by 半仙 on 2023/12/23/023 11:51
 */
object AppCodeUtils {
    /**
     * 是不是阿拉伯语
     */
    fun isAR(): Boolean {
        val appLanguage = MultiLanguages.getAppLanguage().language
        return (appLanguage == "ar" || appLanguage.startsWith("ar_"))
    }

    /**
     * 部分文本是带标点符号的，当切到阿拉伯的时候标点符号在左边,但是切换回其他语言的时候标点符号还在左边
     */
    fun String.arTo(): String {
        return if (!isAR()) {
            BidiFormatter.getInstance(Locale.getDefault()).unicodeWrap(
                this, TextDirectionHeuristics.LTR
            )
        } else {
            BidiFormatter.getInstance(Locale.getDefault()).unicodeWrap(
                this, TextDirectionHeuristics.RTL
            )
        }
    }
}